package com.hh.usercenter.controller;


import com.hh.commonutils.Result;
import com.hh.usercenter.entity.UcenterMember;
import com.hh.usercenter.entity.vo.RegisterVo;
import com.hh.usercenter.service.UcenterMemberService;
import com.hh.vo.UcenterMemberVoGloabl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * <p>
 * 会员表 前端控制器
 * </p>
 *
 * @author hh
 * @since 2021-12-22
 */
@RestController
@RequestMapping("/usercenter/ucenter-member")
public class UcenterMemberController {
    @Autowired
    private UcenterMemberService ucenterMemberService;

    @PostMapping("/register")
    public Result register(@RequestBody RegisterVo registerVo) {
        Result register = ucenterMemberService.register(registerVo);
        return register;
    }

    @PostMapping("/login")
    public Result login(@RequestBody RegisterVo registerVo){
        String token = ucenterMemberService.login(registerVo);
        return Result.success().data("token", token);
    }

    @GetMapping("/author/getInfoByToken/")
    public Result getInfoByToken(HttpServletRequest  request){
        UcenterMember ucenterMember = ucenterMemberService.getInfoByToken(request);
        return Result.success().data("data",ucenterMember);
    }

    @GetMapping("/getUcenterMenberById/{id}")
    public UcenterMemberVoGloabl getUcenterMenberById(@PathVariable("id") String id){
        UcenterMember ucenterMember = ucenterMemberService.getUcenterMenberById(id);
        UcenterMemberVoGloabl ucenterMemberVoGloabl = new UcenterMemberVoGloabl();
        BeanUtils.copyProperties(ucenterMember, ucenterMemberVoGloabl);
        return ucenterMemberVoGloabl;
    }

    @GetMapping("/getRegisterCountOfDay/{date}")
    public int getRegisterCountOfDay(@PathVariable("date") String date){
        int count = ucenterMemberService.getRegisterCountOfDay(date);
        return count;
    }
}

